package desktop.core.square;

import pulpcore.image.CoreImage;
import pulpcore.sprite.ImageSprite;

/**
 * leaf of sprite
 */
public class Square extends ImageSprite implements ComparableSquare, Cloneable {
	private int type;

	/**
	 * @param x
	 *            ，y由它的父Sprite决定
	 * @param w
	 *            ，h由PlayFieldView决定并传递给工厂，几乎是final。
	 */
	public Square(CoreImage image, double x, double y, double w, double h,
			int type) {
		super(image, x, y, w, h);
		this.type = type;
	}

	public boolean containsPoint(double xCheck, double yCheck) {
		return (this.x.get() < xCheck)
				&& (xCheck < this.x.get() + this.width.get())
				&& (this.y.get() < yCheck)
				&& (yCheck < this.y.get() + this.height.get());
	}

	@Override
	public boolean sameTypeAs(ComparableSquare square) {
		return (square != null) && (this.typeAsInt() == square.typeAsInt());
	}

	@Override
	public int typeAsInt() {
		return this.type;
	}

	@Override
	public Object clone() {
		return new Square(this.getImage(), this.x.get(), this.y.get(),
				this.width.get(), this.height.get(), this.type);
	}

}